const jwt = require('jsonwebtoken');

const key = '0215zuiniubi';

// 声明token密钥
let token = jwt.sign({username:"laowang",age:18,sex:"男"},key,{expiresIn:3});

console.log(token);

setTimeout(() => {
    // 验证token
    jwt.verify(token,key,(err,data)=>{
        if(err){
            // JsonWebTokenError token或者签名不对
            // console.log(err.name);
            // TokenExpiredError 过期了
            if(err.name === 'TokenExpiredError'){
                console.log("签名过期");
            }else{
                console.log("token非法");
            }
        }else{
            console.log(data);
        }
    })
}, 4000);